import { AppDispatch } from '..';
import {
  getArticleListByIdAPI,
  ArticleQueryParamsType,
  getArticleDetailByIdAPI,
} from './../../api/article';
// 2. 封装异步Aciton
export const getArticleListByIdAction = ({
  channel_id,
  timestamp = Date.now(),
}: ArticleQueryParamsType) => {
  return async (dispatch: AppDispatch) => {
    const res = await getArticleListByIdAPI({ channel_id, timestamp });
    console.log('res  ----->  ', res);
    // 3. 触发保存的逻辑
    dispatch({
      type: 'article/saveList',
      payload: { ...res.data, channel_id },
    });
  };
};

export const updateArticleListByIdAction = ({
  channel_id,
  timestamp = Date.now(),
}: ArticleQueryParamsType) => {
  return async (dispatch: AppDispatch) => {
    const res = await getArticleListByIdAPI({ channel_id, timestamp });
    dispatch({
      type: 'article/udpatelistById',
      payload: { ...res.data, channel_id },
    });
  };
};
/** 根据id查询文章详情 */
export const getArticleDetailByIdAction = (id: number) => {
  return async (dispatch: AppDispatch) => {
    const res = await getArticleDetailByIdAPI(id);
  };
};
